﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Text;
using CRM.Entity;

using CRM.BLL;
using DP.Web.UI.Controls;
using DP.Web.UI;
using DP.Common;



namespace CRM.Web.Pop
{
    public partial class VehicleInfo : Common.PageBase
    {
        private UserLoginInfo _userLoginInfo;
        public string Modify = "~/VehicleManage/SaleModify.aspx?OPENTYPE=NEWPAGE&VEHICLEID={0}";

        T_SALEVEHICLE_BLL bll = new T_SALEVEHICLE_BLL();
        T_VEHICLECUSTOMER_BLL vehicleCustomerBll = new T_VEHICLECUSTOMER_BLL();
        private T_CUSTOMERTELINDEX_BLL customerTelIndexBll = new T_CUSTOMERTELINDEX_BLL();

        protected override void OnInit(EventArgs e)
        {
            base.VerificationRight = false;
            base.OnInit(e);
            _userLoginInfo = UserLoginInfo.GetLoginInfo();
            PageHelper.SetPrePageUrl(this.Page);

            if (PageHelper.GetQueryString(this.Page, "PageTarget") == "Opener")
            {
                btnClose.Visible = true;
                btnAddVehicle.Visible = false;
            }

        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                GetUrlQueryToControl();
                gvDataBinding();
            }
        }

        #region 页面初始化数据绑定







































































        #endregion

        /// <summary>
        /// 获取 URL 上的参数存入当页面 控件中。
        /// </summary>
        private void GetUrlQueryToControl()
        {
            PageHelper.GetUrlQueryToControl(this.Page);
        }



        /// <summary>
        /// 生成查询条件字符串
        /// </summary>
        private StringBuilder GenerationSQLString()
        {
            StringBuilder sql = new StringBuilder();

            if (!String.IsNullOrEmpty(Request.QueryString["VEHICLEID"]))
            {
                sql.Append(" and VEHICLEID like '%" + Request.QueryString["VEHICLEID"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VINCODE"]))
            {
                sql.Append(" and VINCODE like '%" + Request.QueryString["VINCODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PRODUCTCODE"]))
            {
                sql.Append(" and PRODUCTCODE like '%" + Request.QueryString["PRODUCTCODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["BRANDCODE"]))
            {
                sql.Append(" and BRANDCODE like '%" + Request.QueryString["BRANDCODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VEHICLETYPECODE"]))
            {
                sql.Append(" and VEHICLETYPECODE like '%" + Request.QueryString["VEHICLETYPECODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["SERIESCODE"]))
            {
                sql.Append(" and SERIESCODE like '%" + Request.QueryString["SERIESCODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["MODELSCODE"]))
            {
                sql.Append(" and MODELSCODE like '%" + Request.QueryString["MODELSCODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["ENGINEMODELCODE"]))
            {
                sql.Append(" and ENGINEMODELCODE like '%" + Request.QueryString["ENGINEMODELCODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["ENGINEMANUFACTURERSCODE"]))
            {
                sql.Append(" and ENGINEMANUFACTURERSCODE like '%" + Request.QueryString["ENGINEMANUFACTURERSCODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["BRAND"]))
            {
                sql.Append(" and BRAND like '%" + Request.QueryString["BRAND"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VEHICLETYPE"]))
            {
                sql.Append(" and VEHICLETYPE like '%" + Request.QueryString["VEHICLETYPE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["SERIES"]))
            {
                sql.Append(" and SERIES like '%" + Request.QueryString["SERIES"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["MODELS"]))
            {
                sql.Append(" and MODELS like '%" + Request.QueryString["MODELS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["ENGINEMODEL"]))
            {
                sql.Append(" and ENGINEMODEL like '%" + Request.QueryString["ENGINEMODEL"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["ENGINEMANUFACTURERS"]))
            {
                sql.Append(" and ENGINEMANUFACTURERS like '%" + Request.QueryString["ENGINEMANUFACTURERS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["ENGINENUMBER"]))
            {
                sql.Append(" and ENGINENUMBER like '%" + Request.QueryString["ENGINENUMBER"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["FRAMENUMBER"]))
            {
                sql.Append(" and FRAMENUMBER like '%" + Request.QueryString["FRAMENUMBER"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["RANGE"]))
            {
                sql.Append(" and RANGE like '%" + Request.QueryString["RANGE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["OFFLINEDATEBegin"]))
            {
                sql.Append(" and OFFLINEDATE >= '" + Request.QueryString["OFFLINEDATEBegin"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["OFFLINEDATEEnd"]))
            {
                sql.Append(" and OFFLINEDATE < '" + Request.QueryString["OFFLINEDATEEnd"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["FIRSTSALESDATEBegin"]))
            {
                sql.Append(" and FIRSTSALESDATE >= '" + Request.QueryString["FIRSTSALESDATEBegin"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["FIRSTSALESDATEEnd"]))
            {
                sql.Append(" and FIRSTSALESDATE < '" + Request.QueryString["FIRSTSALESDATEEnd"].Trim() + "'");
            }
            //if (!String.IsNullOrEmpty(Request.QueryString["CUSTOMERID"]))
            //{
            //    sql.Append(" and CUSTOMERID like '%" + Request.QueryString["CUSTOMERID"] + "%'");
            //}
            if (!String.IsNullOrEmpty(Request.QueryString["CUSTOMERNAME"]))
            {
                sql.Append(" and CUSTOMERNAME like '%" + Request.QueryString["CUSTOMERNAME"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["MANUFACTUREDATEBegin"]))
            {
                sql.Append(" and MANUFACTUREDATE >= '" + Request.QueryString["MANUFACTUREDATEBegin"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["MANUFACTUREDATEEnd"]))
            {
                sql.Append(" and MANUFACTUREDATE < '" + Request.QueryString["MANUFACTUREDATEEnd"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PURCHASEDATEBegin"]))
            {
                sql.Append(" and PURCHASEDATE >= '" + Request.QueryString["PURCHASEDATEBegin"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PURCHASEDATEEnd"]))
            {
                sql.Append(" and PURCHASEDATE < '" + Request.QueryString["PURCHASEDATEEnd"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["MARKETDEPARTMENTID"]))
            {
                sql.Append(" and MARKETDEPARTMENTID like '%" + Request.QueryString["MARKETDEPARTMENTID"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["MARKETDEPARTMENTCODE"]))
            {
                sql.Append(" and MARKETDEPARTMENTCODE like '%" + Request.QueryString["MARKETDEPARTMENTCODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["MARKETDEPARTMENTNAME"]))
            {
                sql.Append(" and MARKETDEPARTMENTNAME like '%" + Request.QueryString["MARKETDEPARTMENTNAME"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["DEALERCODE"]))
            {
                sql.Append(" and DEALERCODE like '%" + Request.QueryString["DEALERCODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["DEALERNAME"]))
            {
                sql.Append(" and DEALERNAME like '%" + Request.QueryString["DEALERNAME"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PURCHASEMETHOD"]))
            {
                sql.Append(" and PURCHASEMETHOD like '%" + Request.QueryString["PURCHASEMETHOD"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["ISSUBSIDIES"]))
            {
                sql.Append(" and ISSUBSIDIES like '%" + Request.QueryString["ISSUBSIDIES"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["SALESTYPE"]))
            {
                sql.Append(" and SALESTYPE like '%" + Request.QueryString["SALESTYPE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CONTACTNAME"]))
            {
                sql.Append(" and CONTACTNAME like '%" + Request.QueryString["CONTACTNAME"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CONTACTTEL"]))
            {
                sql.Append(" and CONTACTTEL like '%" + Request.QueryString["CONTACTTEL"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VEHICLESTATUS"]))
            {
                sql.Append(" and VEHICLESTATUS like '%" + Request.QueryString["VEHICLESTATUS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PRODUCTID"]))
            {
                sql.Append(" and PRODUCTID like '%" + Request.QueryString["PRODUCTID"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CFGPRODUCTCODE"]))
            {
                sql.Append(" and CFGPRODUCTCODE like '%" + Request.QueryString["CFGPRODUCTCODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CREATETIMEBegin"]))
            {
                sql.Append(" and CREATETIME >= '" + Request.QueryString["CREATETIMEBegin"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CREATETIMEEnd"]))
            {
                sql.Append(" and CREATETIME < '" + Request.QueryString["CREATETIMEEnd"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CREATEPEOPLEID"]))
            {
                sql.Append(" and CREATEPEOPLEID like '%" + Request.QueryString["CREATEPEOPLEID"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CREATEPEOPLE"]))
            {
                sql.Append(" and CREATEPEOPLE like '%" + Request.QueryString["CREATEPEOPLE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["LASTMODIFYPEOPLEID"]))
            {
                sql.Append(" and LASTMODIFYPEOPLEID like '%" + Request.QueryString["LASTMODIFYPEOPLEID"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["LASTMODIFYPEOPLE"]))
            {
                sql.Append(" and LASTMODIFYPEOPLE like '%" + Request.QueryString["LASTMODIFYPEOPLE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["LASTMODIFYTIMEBegin"]))
            {
                sql.Append(" and LASTMODIFYTIME >= '" + Request.QueryString["LASTMODIFYTIMEBegin"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["LASTMODIFYTIMEEnd"]))
            {
                sql.Append(" and LASTMODIFYTIME < '" + Request.QueryString["LASTMODIFYTIMEEnd"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["REMARK"]))
            {
                sql.Append(" and REMARK like '%" + Request.QueryString["REMARK"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["BUSINESSDIVISIONID"]))
            {
                sql.Append(" and BUSINESSDIVISIONID like '%" + Request.QueryString["BUSINESSDIVISIONID"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["BUSINESSDIVISIONNAME"]))
            {
                sql.Append(" and BUSINESSDIVISIONNAME like '%" + Request.QueryString["BUSINESSDIVISIONNAME"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["BUSINESSDIVISIONCODE"]))
            {
                sql.Append(" and BUSINESSDIVISIONCODE like '%" + Request.QueryString["BUSINESSDIVISIONCODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CARNUMBER"]))
            {
                sql.Append(" and CARNUMBER like '%" + Request.QueryString["CARNUMBER"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CHASSISNO"]))
            {
                sql.Append(" and CHASSISNO like '%" + Request.QueryString["CHASSISNO"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["SERIALNUMBER"]))
            {
                sql.Append(" and SERIALNUMBER like '%" + Request.QueryString["SERIALNUMBER"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["GEARTYPE"]))
            {
                sql.Append(" and GEARTYPE like '%" + Request.QueryString["GEARTYPE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["GEARCODE"]))
            {
                sql.Append(" and GEARCODE like '%" + Request.QueryString["GEARCODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["LICENSECODE"]))
            {
                sql.Append(" and LICENSECODE like '%" + Request.QueryString["LICENSECODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["LASTSALEDATEBegin"]))
            {
                sql.Append(" and LASTSALEDATE >= '" + Request.QueryString["LASTSALEDATEBegin"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["LASTSALEDATEEnd"]))
            {
                sql.Append(" and LASTSALEDATE < '" + Request.QueryString["LASTSALEDATEEnd"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["INVOICECODE"]))
            {
                sql.Append(" and INVOICECODE like '%" + Request.QueryString["INVOICECODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["SALESPRICE"]))
            {
                sql.Append(" and SALESPRICE like '%" + Request.QueryString["SALESPRICE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PRICE"]))
            {
                sql.Append(" and PRICE like '%" + Request.QueryString["PRICE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["COLOR"]))
            {
                sql.Append(" and COLOR like '%" + Request.QueryString["COLOR"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["BULLETINCODE"]))
            {
                sql.Append(" and BULLETINCODE like '%" + Request.QueryString["BULLETINCODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["MODIFYCOUNT"]))
            {
                sql.Append(" and MODIFYCOUNT like '%" + Request.QueryString["MODIFYCOUNT"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["QUICKCODE"]))
            {
                sql.Append(" and QUICKCODE like '%" + Request.QueryString["QUICKCODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["SIMPLELICENCE"]))
            {
                sql.Append(" and SIMPLELICENCE like '%" + Request.QueryString["SIMPLELICENCE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PURPOSE"]))
            {
                sql.Append(" and PURPOSE like '%" + Request.QueryString["PURPOSE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["SUPPLYCODE"]))
            {
                sql.Append(" and SUPPLYCODE like '%" + Request.QueryString["SUPPLYCODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["SUPPLYNAME"]))
            {
                sql.Append(" and SUPPLYNAME like '%" + Request.QueryString["SUPPLYNAME"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["SERIALMENO"]))
            {
                sql.Append(" and SERIALMENO like '%" + Request.QueryString["SERIALMENO"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["STATIONCODE"]))
            {
                sql.Append(" and STATIONCODE like '%" + Request.QueryString["STATIONCODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["EMISSIONS"]))
            {
                sql.Append(" and EMISSIONS like '%" + Request.QueryString["EMISSIONS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["STATIONNAME"]))
            {
                sql.Append(" and STATIONNAME like '%" + Request.QueryString["STATIONNAME"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CUSTOMERCODE"]))
            {
                sql.Append(" and VinCode in (Select VinCode  from T_VehicleCustomer where CUSTOMERCODE = '" + Request.QueryString["CUSTOMERCODE"] + "' ) ");
            }
            if(!String.IsNullOrEmpty(Request.QueryString["PHONE"]))
            {
                sql.Append(String.Format(" and (OwnersMobilePhone = '{0}' or OwnersOfficePhone = '{0}' or OwnersHomePhone = '{0}' or ContactTel = '{0}' ) ", Request.QueryString["PHONE"]));
            }

            if (sql.Length == 0)
            {
                return sql;
            }

            if (!UserLoginInfo.IsAdministrator())
            {
                sql.Append(" and BUSINESSDIVISIONCODE = '" + _userLoginInfo.UserEntity.BUSINESSDIVISIONCODE.Trim() + "'");
                UserType userType = UserLoginInfo.GetCurrentUserType();
                switch (userType)
                {
                    case UserType.中心部门:
                    case UserType.供应商:
                    case UserType.市场部:
                        {

                        }
                        break;
                    case UserType.服务商:
                        {
                            sql.Append(String.Format(" and STATIONCODE = '{0}' ", UserLoginInfo.GetCurrentDepartmentCode()));
                        }
                        break;
                    case UserType.经销商:
                        {
                            sql.Append(String.Format(" and DEALERCODE = '{0}' ", UserLoginInfo.GetCurrentDepartmentCode()));
                        }
                        break;
                }
            }
            return sql;

        }

        /// <summary>
        /// 页面数据绑定
        /// </summary>
        private void gvDataBinding()
        {

            #region 查询条件字符串
            StringBuilder sql = GenerationSQLString();
            #endregion


            List<T_SALEVEHICLE_Entity> list;

            if (sql.ToString() == string.Empty)
            {
                gvList.DataSource = new List<T_SALEVEHICLE_Entity>();
                gvList.DataKeyNames = new string[] { "VEHICLEID", "BUSINESSDIVISIONCODE", "BUSINESSDIVISIONID", "BUSINESSDIVISIONNAME", "DEALERCODE", "ENGINENUMBER", "VINCODE" };
                gvList.DataBind();
                return;
            }

            //获取总的记录条数
            gvList.RecordCount = (int)bll.GetCount(sql.ToString());

            list = bll.GetList(sql.ToString(), gvList.CurrentPageIndex * gvList.PageSize, gvList.PageSize, gvList.SortConditions);

            gvList.DataSource = list;
            gvList.DataKeyNames = new string[] { "VEHICLEID", "BUSINESSDIVISIONCODE", "BUSINESSDIVISIONID", "BUSINESSDIVISIONNAME", "DEALERCODE", "ENGINENUMBER", "VINCODE" };
            gvList.DataBind();

        }


        /// <summary>
        /// Selecteds the command.
        /// </summary>
        /// <param name="productCode">The product code.</param>
        /// <param name="brand">The brand.</param>
        /// <param name="vehicleType">Type of the vehicle.</param>
        /// <param name="series">The series.</param>
        /// <param name="models">The models.</param>
        /// <param name="engineModel">The engine model.</param>
        /// <param name="engineManufacturers">The engine manufacturers.</param>
        /// <param name="vinCode">The vin code.</param>
        /// <param name="engineNumber">The engine number.</param>
        /// <param name="dealerCode">The dealer code.</param>
        /// <param name="stationCode">The station code.</param>
        /// <param name="customerCode">The customer code.</param>
        /// <param name="customerName">Name of the customer.</param>
        /// <param name="ownersMobilePhone">The owners mobile phone.</param>
        /// <param name="ownersHomePhone">The owners home phone.</param>
        /// <returns></returns>
        public string SelectedCommand(string productCode, string brand, string vehicleType, string series, string models, string engineModel, string engineManufacturers, string vinCode, string engineNumber, string dealerCode, string stationCode, string vehicleMarkCode, string customerCode, string customerName, string ownersMobilePhone, string ownersHomePhone, DateTime? purchaseDate)
        {
            string fun = "return setValue('{0}','{1}','{2}','{3}','{4}','{5}','{6}', '{7}', '{8}', '{9}', '{10}', '{11}', '{12}', '{13}', '{14}', '{15}', '{16}'); ";
            fun = String.Format(fun, UserLoginInfo.FilterString(productCode), UserLoginInfo.FilterString(brand), UserLoginInfo.FilterString(vehicleType), UserLoginInfo.FilterString(series), UserLoginInfo.FilterString(models), UserLoginInfo.FilterString(engineModel), UserLoginInfo.FilterString(engineManufacturers), UserLoginInfo.FilterString(vinCode), UserLoginInfo.FilterString(engineNumber), UserLoginInfo.FilterString(dealerCode), UserLoginInfo.FilterString(stationCode), UserLoginInfo.FilterString(vehicleMarkCode), UserLoginInfo.FilterString(customerCode), UserLoginInfo.FilterString(customerName), UserLoginInfo.FilterString(ownersMobilePhone), UserLoginInfo.FilterString(ownersHomePhone), purchaseDate.HasValue ? purchaseDate.Value.ToString("yyyy-MM-dd") : "");
            return fun;
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string url = HttpContext.Current.Request.Url.AbsolutePath;
            PageHelper.GetControlToUrlQuery(this.Page, ref url);
            url = StringHelper.UrlReplare(url, "CUSTOMERID", PageHelper.GetQueryString(this.Page, "CUSTOMERID"));
            Response.Redirect(url);

        }


        #region GridView 事件
        /// <summary>
        /// GridView 删除事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvList_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            

        }

        /// <summary>
        /// GridView 行数据绑定事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            string temp = string.Empty;
            switch (e.Row.RowType)
            {
                case DataControlRowType.DataRow:
                    {

                        GridView gv = (sender as GridView);
                        for (int i = 0; i < gv.Columns.Count; i++)
                        {
                            TemplateField tf = gv.Columns[i] as TemplateField;
                            if (tf != null)
                            {
                                #region 存储值 转换成  显示值
                                switch (tf.HeaderText)
                                {
                                    case "操作":
                                        {
                                            e.Row.Cells[i].Attributes.Add("style", "white-space: nowrap;");
                                        }
                                        break;
                                    default:
                                        {
                                            e.Row.Cells[i].Attributes.Add("style", "white-space: nowrap;");
                                        }
                                        break;

                                }
                                #endregion
                            }

                            BoundField bf = gv.Columns[i] as BoundField;
                            if (bf != null)
                            {
                                #region 存储值 转换成  显示值
                                switch (bf.DataField)
                                {
                                    case "ISHASGPS":
                                        {
                                            try
                                            {
                                                temp = e.Row.Cells[i].Text.Trim();
                                                temp = ((IsHasGPS)Enum.Parse(typeof(IsHasGPS), temp)).ToString();
                                                e.Row.Cells[i].Text = temp;
                                            }
                                            catch (Exception)
                                            {
                                                //throw;
                                            }
                                        }
                                        break;
                                    default:
                                        {

                                        }
                                        break;
                                }
                                #endregion
                            }
                        }
                    }
                    break;
                case DataControlRowType.Header:
                    {

                    }
                    break;
                case DataControlRowType.Pager:
                    {

                    }
                    break;
                case DataControlRowType.EmptyDataRow:
                    {


                    }
                    break;
                default:

                    break;
            }

        }

        protected void gvList_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            switch (e.CommandName.ToString())
            {
                case "Associate":
                    {
                        if (!String.IsNullOrEmpty(e.CommandArgument.ToString()))
                        {
                            T_CUSTOMERTELINDEX_Entity customertelindexEntity = customerTelIndexBll.GetEntity("CUSTOMERID", PageHelper.GetQueryString(this.Page, "CUSTOMERID"));
                            if (customertelindexEntity != null)
                            {
                                try
                                {
                                    GridViewRow gvr = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
                                    var dataKey = gvList.DataKeys[gvr.RowIndex];
                                    T_VEHICLECUSTOMER_Entity vehicleCustomerEntity = new T_VEHICLECUSTOMER_Entity();
                                    vehicleCustomerEntity.VINCODE = e.CommandArgument.ToString();
                                    vehicleCustomerEntity.BUSINESSDIVISIONCODE = dataKey.Values["BUSINESSDIVISIONCODE"].ToString();
                                    vehicleCustomerEntity.BUSINESSDIVISIONID = StringHelper.ToInt(dataKey.Values["BUSINESSDIVISIONID"].ToString());
                                    vehicleCustomerEntity.BUSINESSDIVISIONNAME = dataKey.Values["BUSINESSDIVISIONNAME"].ToString();
                                    vehicleCustomerEntity.CREATEPEOPLE = _userLoginInfo.UserEntity.USERNAME;
                                    vehicleCustomerEntity.CREATEPEOPLEID = _userLoginInfo.UserEntity.USERID;
                                    vehicleCustomerEntity.CREATETIME = DateTime.Now;
                                    vehicleCustomerEntity.CUSTOMERCODE = customertelindexEntity.CUSTOMERCODE;
                                    vehicleCustomerEntity.DEALERCODE = dataKey.Values["DEALERCODE"].ToString();
                                    vehicleCustomerEntity.ENGINENUMBER = dataKey.Values["ENGINENUMBER"].ToString();
                                    vehicleCustomerEntity.IDNUMBER = customertelindexEntity.IDNUMBER;
                                    vehicleCustomerEntity.CUSTOMERID = customertelindexEntity.CUSTOMERID;
                                    vehicleCustomerBll.Insert(vehicleCustomerEntity);
                                    Response.Redirect(Request.RawUrl);
                                }
                                catch
                                {

                                }
                            }
                        }
                    }
                    break;
                default:
                    {


                    }
                    break;
            }
        }

        /// <summary>
        /// GridView 行创建事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvList_RowCreated(object sender, GridViewRowEventArgs e)
        {
            switch (e.Row.RowType)
            {
                case DataControlRowType.DataRow:
                    {

                    }
                    break;
                case DataControlRowType.Header:
                    {

                    }
                    break;
                case DataControlRowType.Pager:
                    {

                    }
                    break;
                case DataControlRowType.EmptyDataRow:
                    {


                    }
                    break;
                default:

                    break;
            }

        }

        /// <summary>
        /// GridView 排序事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvList_Sorting(object sender, GridViewSortEventArgs e)
        {

        }
        #endregion


    }
}
